<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<div class="yuSuo clearfix" style="float:left;">
        <form id="searchFrom">
            <input id="status" name="status" type="hidden" value="{$params.status}"/>
            <?php if($params['status']== 1): ?> 
            <input type="text" name="search_key" value="{$params.search_key}"  placeholder="登录名/联系人姓名/联系电话/集团名称"  class="suoDian suoDian1" style="width:350px">
             <?php elseif($params['status']==2): ?> 
            <input type="text" name="search_key" value="{$params.search_key}"  placeholder="登录名/联系人姓名/联系电话/4S店名称"  class="suoDian suoDian1" style="width:350px">
            <?php endif;?>
            <input type="button" onclick="search();" value="搜索" class="suoSou" style="width:80px;">
        </form>
</div>
<div class="xinzeng clearfix">
  <?php if($params['status']==1): ?>
    <a class="newBtn" href="javascript:;" onclick="popup()" >添加集团账号</a>
  <?php elseif($params['status']==2): ?> 
    <a class="newBtn" href="javascript:;" onclick="popup()" >添加4s店账号</a>
  <?php endif;?>
</div>
<!--弹出窗口-->
<style>
</style>
<div class="yunBei"></div>
<div class="tanShang" style="width:550px;top:20%">
  <?php if($params['status']==1): ?>
      <h3>添加集团账号</h3>
  <?php elseif($params['status']==2): ?>
      <h3>添加4S店账号</h3>
  <?php endif;?>
    
    <ul style="padding-left:10px;">
        <li class="clearfix">
            <span>用户名:</span>
            <input type="text" name="user_name" id='user_name' value="" />
        </li>
         <li class="clearfix">
            <span>姓名:</span>
            <input type="text" name="real_name" id="real_name" value="" />
        </li>
         <li class="clearfix">
            <span>手机号:</span>
            <input type="text" name="phone" id="phone" value="" />
        </li>
         <li class="clearfix">
            <?php if($params['status']==1): ?>
            <span>集团:</span>
            <select name="b_id" id="b_id" >
                <option value="">请选择所属集团</option>
                <volist name='allinfo' id='info'>
                  <option value="{$info.bid}" >{$info.b_name}</option>
                </volist>
            </select>
            <?php elseif($params['status']==2): ?>
            <span>4s店:</span>
            <select name="city" id="city" >
                <option value="">请选择城市</option>
                <?php foreach ($bc_city as $key => $value): ?>
                  <option value="{$key}">{$value}</option>
                <?php endforeach ?>
            </select>
            <select name="f_id" id="f_id" >
                <option value="">请选择所属4s店</option>
            </select>
            <?php endif;?>
        </li>
        <li class="clearfix">
         <?php if($params['status']==1): ?>
              <input type="button" value="确定" class="queding" id="add_bloc" />
            <?php elseif($params['status']==2): ?>
              <input type="button" value="确定" class="queding" id="add_fours"/>
            <?php endif;?>
           <input type="button" value="取消" class="quxiao"/>
       </li>
    </ul>
</div>
<!--弹出窗口结束-->

<div class="yuList">
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>账号id</th>       
        <th>登录用户名</th>
        <th>姓名</th>   
        <th>电话</th>
        <?php if($params['status']==1): ?>
        <th>集团名称</th>
        <?php elseif($params['status']==2): ?>
        <th>4s店名称</th>  
        <?php endif;?>
        <th>账户状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      <volist name="list" id="list" key="k">
        <tr>
          <?php if($params['status']==1): ?>
            <td>{$list.bu_id}</td>
          <?php elseif($params['status']==2): ?>
            <td>{$list.fu_id}</td>
          <?php endif;?>
          <td>{$list.user_name}</td>
          <td>{$list.real_name}</td>
          <td>{$list.phone}</td> 
          <?php if($params['status']==1): ?>
          <td>{$list.b_name}</td>
          <?php elseif($params['status']==2): ?>
          <td>{$list.f_name}</td>
          <?php endif;?>
          <td>{$list['status']?'禁用':'启用'}</td>
           <td>

            <if condition="($list.status eq 1)">
              <a href="" onclick="return ci_op('{$list.uid}',0);">启用</a> 
            <else />
              <a href="" onclick="return ci_op('{$list.uid}',1);">禁用</a> 
            </if>

            <?php if($params['status']==1): ?>
              <a href="/fours/bloc_eidt/uid/{$list.uid}" >编辑</a>
            <?php elseif($params['status']==2): ?>
              <a href="/fours/fours_eidt/uid/{$list.uid}">编辑</a>
            <?php endif;?>
              <a href="javascript:;" onclick="restpwd('{$list.uid}');">重置密码</a> 
           </td>       
        </tr>
      </volist>
    </tbody>
  </table>
 </div>
 <div class="pageFaye"><div class="pager">{$page}</div><div class="clear"></div></div>
</div>
<script>
</script>

<script>

$("#city").change(function(){
    var city_id = $(this).val();
    $.get("/Fours/get_city",{"city_id":city_id},function(data){
        var optstr = '';
        if(data.code==200){
               $.each(data.data,function(k,val){
                optstr += "<option value='" + val.fid + "'>"+ val.f_name +"</option>"
               })
        }
        $("#f_id").html(optstr);
    },"json");
});

function ci_op(uid,op_type){
  var post_data = {uid:uid,op_type:op_type};
  $.post('/Fours/ci_op',post_data,function(res){
    if(res.code==200){
      delay_alert('操作成功!');
      setTimeout(function(){
        window.location.reload(); 
      },300);
    }else{
      delay_alert(res.msg);
    }
  },'json');
  return false;
};


$(".tanShang ul li .quxiao").click(function(){
    $(".tanShang").fadeOut();
    $(".yunBei").css("display","none");
});

//表单弹窗
  function popup() {
      $(".yunBei").fadeIn();
      $(".tanShang").fadeIn(); 
      $("#b_id").select2();
      $("#f_id").select2();
  }


  //添加4s账号提交
    $("#add_fours").on('click', function () {
        var f_id = $('#f_id').val();
        var user_name = $('input[name=user_name]').val();
        var real_name = $('input[name=real_name]').val();
        var phone = $('input[name=phone]').val();
        var param = {
            'f_id': f_id,
            'user_name': user_name,
            'real_name': real_name,
            'phone': phone
        };
        $.post('/fours/add_fours', param, function (data) {
            if (data.code == '200') {
                $(".yunBei").css("display", "none");
                $(".tanShang").fadeOut();
                btn_alert(data.msg);
                get_list(2);
            } else {
                shibai_alert(data.msg);
            }
        }, "json");

    });


  //添加集团账号提交
    $("#add_bloc").on('click', function () {
        var b_id = $('#b_id').val();
        var user_name = $('input[name=user_name]').val();
        var real_name = $('input[name=real_name]').val();
        var phone = $('input[name=phone]').val();
        var param = {
            'b_id': b_id,
            'user_name': user_name,
            'real_name': real_name,
            'phone': phone
        };
        $.post('/fours/add_bloc', param, function (data) {
            if (data.code == '200') {
                $(".yunBei").css("display", "none");
                $(".tanShang").fadeOut();
                btn_alert(data.msg);
                get_list(1);
            } else {
                shibai_alert(data.msg);
            }
        }, "json");

    });


//重置密码
function restpwd(username){
        confirmAAA('<div style="color:red">确认重置密码吗？</div>', confirm11);
        function confirm11() {
            $('.determine').click(function() {
                colse_hideA();
                arestpwd(username);
            });
        }
    }

    function confirmAAA(text,callback){
        var html='<div class="chenggong1"><span class="paidan">'+text+'</span><div class="shenhei-btn"><input type="button" value="确定" class="determine" /><input type="button" value="取消" class="cancel" onclick="colse_hide()" /></div></div>'
        $(".yunBei").css("display","block");
        $(document.body).append(html);
        $(".chenggong1").css("display","block");
        if(typeof(callback)!="undefined"){
            callback();
        }
    }
    function colse_hideA(){
        $(".yunBei").css("display","none");
        $(".chenggong1").fadeOut('slow',function(){
            $(".chenggong1").remove();
        });
    }   
    function arestpwd(uid){
        $.post("/fours/restpwd",{'uid':uid}, function (data) {
            if(data.code=='200'){
                var curr_char = $('input[name=char]').val();
                btn_alert(data.msg,1000,function(){
                    $(".fchar").each(function (i) {
                        if ($(this).text().trim() == curr_char) {
                            $(this).click();
                        }
                    });
                });
            }else{
                shibai_alert(data.msg);
            }
        }, "json");
    }
</script>